Setup SUGO-Cloud

First of all, you need to setup sugo-cloud on public network so that spot and terminal can access it.

#!/usr/bin/env node
 
/**
 * This is an example to setup cloud server
 */
 
'use strict'
 
const sugoCloud = require('sugo-cloud')
 
const co = require('co')
 
co(function * () {
  // Start sugo-cloud server
  let cloud = yield sugoCloud({
    // Options
    port: 3000
  })
 
  console.log(`SUGO Cloud started at port: ${cloud}`)
 
  return cloud
}).catch((err) => { /* ... */ })

 Run SUGO-Spot

Run sugo-spot on local network where your machine or sensors exists and access to the sugo-cloud.

#!/usr/bin/env node
 
/**
 * This is an example to run local spot server
 */
 
'use strict'
 
const sugoSpot = require('sugo-spot')
const co = require('co')
 
 
co(function * () {
  let spot = sugoSpot(CLOUD_URL, {
    key: 'my-spot-01',
    interfaces: {
      // Add plugin to provide shell interface
      shell: require('sugo-spot-shell')({})
    }
  })
 
// Connect to cloud server
  yield spot.connect()
}).catch((err) => console.error(err))

 Setup SUGO-Cloud

Connect to remote spot from sugo-terminal via cloud.

#!/usr/bin/env node
 
/**
 * This is an example to use terminal to connect remote spot
 */
'use strict'
 
const co = require('co')
const sugoTerminal = require('sugo-terminal')
 
const CLOUD_URL = 'my-sugo-cloud.example.com'
const TARGET_SPOT_ID = 'my-spot-01'
 
co(function * () {
  let terminal = sugoTerminal(CLOUD_URL, {})
 
// Connect to the target spot
  let spot = yield terminal.connect(TARGET_SPOT_ID)
  let shell = spot.shell() // Get bash interface
 
  // Trigger ls command on remote spot
  {
    let lsResult = yield shell.exec('ls -la /opt/shared')
    console.log(lsResult)
  }
 
  // Pipe std out
  {
    let out = (chunk) => process.stdout.write(chunk)
    shell.on('stdout', out)
    shell.spawn('tail -f /var/log/app.log') // Trigger tailing without blocking
    yield new Promise((resolve) => setTimeout(() => resolve(), 3000)) // Block for duration
    shell.off('stdout', out)
  }
 
  // Run reboot command
  yield shell.exec('reboot')
}).catch((err) => console.error(err))